from abc import ABC, abstractmethod
from enum import IntEnum, auto


# 定义枚举类型来表示不同的策略
class FileType(IntEnum):
    CSV = auto()
    EXCEL = auto()


# 每个策略包装成一个类


class ProcessStrategy(ABC):
    @abstractmethod
    def process_file(self, file_path):
        pass


class CSVProcessor(ProcessStrategy):
    def process_file(self, file_path):
        print(f"Processing CSV file: {file_path}")


class ExcelProcessor(ProcessStrategy):
    def process_file(self, file_path):
        print(f"Processing Excel file: {file_path}")


class FileProcessor:
    def __init__(self, file_path, file_type: FileType):
        self.file_path = file_path
        self.strategy = self._select_strategy(file_type)

    def _select_strategy(self, file_type: FileType):
        # 根据文件类型选择策略
        if file_type in STRATEGY_MAP:
            return STRATEGY_MAP[file_type]
        else:
            raise ValueError(f"Unsupported file type: {file_type}")

    def process_file(self):
        self.strategy.process_file(self.file_path)


STRATEGY_MAP = {
    FileType.CSV: CSVProcessor(),
    FileType.EXCEL: ExcelProcessor(),
}

if __name__ == "__main__":
    csv_processor = CSVProcessor()
    excel_processor = ExcelProcessor()

    file_processor = FileProcessor("file.csv", FileType.CSV)
    file_processor.process_file()

    file_processor = FileProcessor("file.xlsx", FileType.EXCEL)
    file_processor.process_file()
